package main

func replaceElements(arr []int) []int {
	result := make([]int, len(arr))
	result[len(arr)-1] = -1
	max := -1
	for i := len(arr) - 1; i > 0; i-- {
		if arr[i] > max {
			max = arr[i]
		}
		result[i-1] = max
	}
	return result
}

func main() {
	arr := []int{17,18,5,4,6,1}
	res := replaceElements(arr)
	println(res)
}